home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / DEMON / RISCOS2 / TCP_131S.ARC / c / IPDUMP < prev    next >
Text File  |  1992-03-05  |  2KB  |  84 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9. #include "netuser.h"
  10. #include "tcp.h"
  11. #include "udp.h"
  12. #include "icmp.h"
  13. #include "misc.h"
  14.  
  15. void ip_dump(struct mbuf **bpp, int check)
  16. {
  17.         struct ip ip;
  18.         int16 ip_len;
  19.         int16 offset;
  20.         int16 length;
  21.         int16 csum;
  22.  
  23.         if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.                 return; 
  25.  
  26.         twprintf("IP:");
  27.         /* Sneak peek at IP header and find length */
  28.         ip_len = ((*bpp)->data[0] & 0xf) << 2;
  29.         if(ip_len < IPLEN){
  30.                 twprintf(" bad header\n");
  31.                 return;
  32.         }
  33.         if(check)
  34.                 csum = cksum(NULLHEADER,*bpp,ip_len);
  35.         else
  36.                 csum = 0;
  37.  
  38.         ntohip(&ip,bpp);        /* Can't fail, we've already checked ihl */
  39.  
  40.         /* Trim data segment if necessary. */
  41.         length = ip.length - ip_len;    /* Length of data portion */
  42.         trim_mbuf(bpp,length);  
  43.         twprintf(" len %u",ip.length);
  44.         twprintf(" %s",inet_ntoa(ip.source));
  45.         twprintf("->%s ihl %u ttl %u",
  46.                 inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  47.         if(ip.tos != 0)
  48.                 twprintf(" tos %u",uchar(ip.tos));
  49.         offset = (ip.fl_offs & F_OFFSET) << 3;
  50.         if(offset != 0 || (ip.fl_offs & MF))
  51.                 twprintf(" id %u offs %u",ip.id,offset);
  52.         if(ip.fl_offs & DF)
  53.                 twprintf(" DF");
  54.         if(ip.fl_offs & MF){
  55.                 twprintf(" MF");
  56.                 check = 0;      /* Bypass host-level checksum verify */
  57.         }
  58.         if(csum != 0)
  59.                 twprintf(" CHECKSUM ERROR (%u)",csum);
  60.  
  61.         if(offset != 0){
  62.                 twprintf("\n");
  63.                 return;
  64.         }
  65.         switch(uchar(ip.protocol)){
  66.         case TCP_PTCL:
  67.                 twprintf(" prot TCP\n");
  68.                 tcp_dump(bpp,ip.source,ip.dest,check);
  69.                 break;
  70.         case UDP_PTCL:
  71.                 twprintf(" prot UDP\n");
  72.                 udp_dump(bpp,ip.source,ip.dest,check);
  73.                 break;
  74.         case ICMP_PTCL:
  75.                 twprintf(" prot ICMP\n");
  76.                 icmp_dump(bpp,ip.source,ip.dest,check);
  77.                 break;
  78.         default:
  79.                 twprintf(" prot %u\n",uchar(ip.protocol));
  80.                 break;
  81.         }
  82. }
  83.  
  84.